package com.tang.model;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/8 20:48
 * @Desc
 * @Remarks
 */
public class DiscountStrategyFactory {

    public static final Map<String, IDiscountStrategy> maps = new HashMap<>();

    static {
        maps.put(StrategyKey.CASH, new CashStrategy());
        maps.put(StrategyKey.GROUP, new GroupStrategy());
        maps.put(StrategyKey.ANNUAL, new AnnualStrategy());
        maps.put(StrategyKey.NORMAL, new NormalStrategy());
    }

    private DiscountStrategyFactory() {
    }

    public static final IDiscountStrategy defaultStrategy = new NormalStrategy();


    public static IDiscountStrategy getStrategy(String name) {
        if (maps.containsKey(name)) {
            return maps.get(name);
        }
        return defaultStrategy;
    }

    private interface StrategyKey {
        public static final String CASH = "cash";
        public static final String GROUP = "group";
        public static final String ANNUAL = "annual";
        public static final String NORMAL = "normal";
    }

}
